package com.ytd.common.dialog;

import android.content.Context;
import android.view.Gravity;
import android.widget.TextView;

import com.ytd.common.R;


public class NormalDialog extends HideNavigationDialog {

    private CallBack mCallBack;

    private TextView tvTitle;
    private TextView tvText;
    private TextView btnOk;
    private TextView btnNo;

    public void setCallBack(CallBack callBack) {
        mCallBack = callBack;
    }

    public NormalDialog(Context context, boolean cancelable) {
        super(context);//设置样式
        getWindow().setGravity(Gravity.CENTER);
        setContentView(R.layout.dialog_normal);
        tvTitle = (TextView) findViewById(R.id.tv_title);
        tvText = (TextView) findViewById(R.id.dialog_txt);
        btnOk = (TextView) findViewById(R.id.dialog_ok);
        btnNo = (TextView) findViewById(R.id.dialog_no);
        this.setCanceledOnTouchOutside(cancelable);
        //设置点击返回键不消失
        this.setCancelable(cancelable);
        btnOk.setOnClickListener(view -> {
            if (mCallBack != null) {
                mCallBack.onClickOk();
            }
            dismiss();
        });
        btnNo.setOnClickListener(view -> {
            if (mCallBack != null) {
                mCallBack.dismiss();
            }
            dismiss();
        });
    }

    public void setBtnText(String ok, String no) {
        btnOk.setText(ok);
        btnNo.setText(no);
    }

    public void setTitle(String title) {
        tvTitle.setText(title);
    }

    public void setText(String text) {
        tvText.setText(text);
    }

    public interface CallBack {
        void dismiss();

        void onClickOk();
    }
}
